<?php	namespace Hdphp\Libs;

class SmartyView {
	protected static $smarty = null;
	
	public function __construct() 
	{
//		echo 1;
		if (!is_null(self::$smarty)) return;
			
		//smarty类是全局空间
		$smarty = new \Smarty();
		//模板目录
		$path = "App/" . MODULE . "/View/" . CONTROLLER;
		$smarty -> template_dir = $path;
		//编译目录
		$path = "Storge/compile/" . MODULE . "/" . CONTROLLER;
		is_dir($path) || mkdir($path, 0777, true);
		$smarty -> compile_dir = $path;
//		//缓存目录
		$path = "Storge/cache/" . MODULE . "/" . CONTROLLER;
		is_dir($path) || mkdir($path, 0777, true);
		$smarty -> cache_dir = $path;
//		//是否缓存
		$smarty -> caching = C("SMARTY_CACHING");
//		//缓存时间
		$smarty -> cache_lifetime = C("SMARTY_CACHING_LIFETIME");
//		//开始定界符
		$smarty -> left_delimiter = C("SMARTY_LEFT_DELIMITER");
//		//结束定界符
		$smarty -> right_delimiter = C("SMARTY_RIGHT_DELIMITER");
		self::$smarty=$smarty;
	}

	//自定义dislay
	protected function display($tpl = null)
	{
		//如果自己不传参数，就默认找相同名字的文件
		if (is_null($tpl)) $tpl = ACTION . ".php";
			
		self::$smarty->display($tpl);

	}
	
	//自定义assign
	protected function assign($var,$value)
	{
		self::$smarty->assign($var,$value);
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
